# coding=utf-8
# __author__ = "James Zhang"
# !/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function, division

from sqlalchemy import Column
from sqlalchemy.types import String, Text, DateTime

from core.db.base import BaseModel


class Session(BaseModel):
    """
    以下为django部分的代码,用tornado重新进行实现,但还没有进行验证!!!

        session_key = models.CharField(_('session key'), max_length=40,
                                   primary_key=True)
        session_data = models.TextField(_('session data'))
        expire_date = models.DateTimeField(_('expire date'), db_index=True)
        objects = SessionManager()

        class Meta:
            db_table = 'django_session'
            verbose_name = _('session')
            verbose_name_plural = _('sessions')

        def __str__(self):
            return self.session_key

        def get_decoded(self):
            return SessionStore().decode(self.session_data)
    """
    session_key = Column(String(40), primary_key=True)
    session_data = Column(Text())
    expire_date = Column(DateTime(), index=True)

    # __table_args__ = (Index('user_index', 'first_name', "last_name"),)

    def __repr__(self):
        return self.session_key


class SessionManager(object):
    """
    对Session进入管理, 这段代码待实现, 暂时可以先不用管: django.contrib.session.models.SessionManager

        class SessionManager(models.Manager):
        use_in_migrations = True

        def encode(self, session_dict):
            return SessionStore().encode(session_dict)

        def save(self, session_key, session_dict, expire_date):
            s = self.model(session_key, self.encode(session_dict), expire_date)
            if session_dict:
                s.save()
            else:
                s.delete()  # Clear sessions with no data.
            return s
    """
    pass
